home *** CD-ROM | disk | FTP | other *** search
/ MacAddict 83 / MacAddict_083_2003-07.iso / mac / Software / Development / VLC Source 0.5.3.dmg / include / httpd.h < prev    next >
C/C++ Source or Header  |  2003-03-14  |  4KB  |  120 lines

  1. /*****************************************************************************
  2.  * httpd.h
  3.  *****************************************************************************
  4.  * Copyright (C) 2001-2003 VideoLAN
  5.  * $Id: httpd.h,v 1.4 2003/03/15 00:09:31 fenrir Exp $
  6.  *
  7.  * Authors: Laurent Aimar <fenrir@via.ecp.fr>
  8.  *
  9.  * This program is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2 of the License, or
  12.  * (at your option) any later version.
  13.  *
  14.  * This program is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with this program; if not, write to the Free Software
  21.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111, USA.
  22.  *****************************************************************************/
  23.  
  24. typedef struct httpd_t          httpd_t;
  25.  
  26. typedef struct httpd_host_t     httpd_host_t;
  27.  
  28. typedef struct httpd_file_t     httpd_file_t;
  29. //typedef struct httpd_stream_t   httpd_stream_t;
  30. typedef httpd_file_t httpd_stream_t;
  31.  
  32. typedef struct httpd_file_callback_args_t httpd_file_callback_args_t;
  33. typedef int (*httpd_file_callback)( httpd_file_callback_args_t *p_args, uint8_t *p_request, int i_request, uint8_t **pp_data, int *pi_data );
  34.  
  35. typedef struct httpd_sys_t httpd_sys_t;
  36.  
  37. struct httpd_t
  38. {
  39.     VLC_COMMON_MEMBERS
  40.  
  41.     module_t        *p_module;
  42.     httpd_sys_t     *p_sys;
  43.  
  44.     httpd_host_t   *(*pf_register_host)     ( httpd_t *, char *, int );
  45.     void            (*pf_unregister_host)   ( httpd_t *, httpd_host_t * );
  46.  
  47.     httpd_file_t   *(*pf_register_file)     ( httpd_t *,
  48.                                               char *psz_file, char *psz_mime,
  49.                                               char *psz_user, char *psz_password,
  50.                                               httpd_file_callback pf_get,
  51.                                               httpd_file_callback pf_post,
  52.                                               httpd_file_callback_args_t *p_args );
  53.     void            (*pf_unregister_file)   ( httpd_t *, httpd_file_t * );
  54.  
  55.     httpd_stream_t *(*pf_register_stream)   ( httpd_t *,
  56.                                               char *psz_file, char *psz_mime,
  57.                                               char *psz_user, char *psz_password );
  58.     int             (*pf_send_stream)       ( httpd_t *,
  59.                                               httpd_stream_t *,
  60.                                               uint8_t *, int );
  61.     int             (*pf_header_stream)     ( httpd_t *,
  62.                                               httpd_stream_t *,
  63.                                               uint8_t *, int );
  64.     void            (*pf_unregister_stream) ( httpd_t *, httpd_stream_t * );
  65. };
  66.  
  67. /*
  68.  * httpd_Find:
  69.  *
  70.  *      Return the running httpd instance
  71.  *      (if none and b_create then a new one is created)
  72.  */
  73. static inline httpd_t* httpd_Find( vlc_object_t *p_this, vlc_bool_t b_create )
  74. {
  75.     httpd_t *p_httpd = NULL;
  76.  
  77.     p_httpd = vlc_object_find( p_this, VLC_OBJECT_HTTPD, FIND_ANYWHERE );
  78.     if( !p_httpd )
  79.     {
  80.         msg_Info(p_this, "creating new http daemon" );
  81.         if( !b_create )
  82.         {
  83.             return( NULL );
  84.         }
  85.  
  86.         p_httpd = vlc_object_create( p_this, VLC_OBJECT_HTTPD );
  87.         if( !p_httpd )
  88.         {
  89.             msg_Err( p_this, "out of memory" );
  90.             return( NULL );
  91.         }
  92.  
  93.         p_httpd->p_module = module_Need( p_httpd, "httpd", "" );
  94.  
  95.         if( !p_httpd->p_module )
  96.         {
  97.             msg_Err( p_this, "no suitable httpd module" );
  98.             vlc_object_destroy( p_httpd );
  99.             return( NULL );
  100.         }
  101.  
  102.         vlc_object_yield( p_httpd );
  103.         vlc_object_attach( p_httpd, p_this->p_vlc );
  104.     }
  105.  
  106.     return( p_httpd );
  107. }
  108.  
  109. static inline void  httpd_Release( httpd_t *p_httpd )
  110. {
  111.     vlc_object_release( p_httpd );
  112.     if( p_httpd->i_refcount <= 0 )
  113.     {
  114.         vlc_object_detach( p_httpd );
  115.     }
  116. }
  117.  
  118.  
  119.  
  120.